﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Common;
using Northwind.Domain;

namespace Ex07
{
    class Program
    {
        static void Main(string[] args)
        {
            var db = new NorthwindEntities();

            //Insert 添加
            db.Customers.AsEnumerable().Dump();
            //1.有主键值的做法--
            //Customer cust = new Customer { ID = 1000, Name = "Bloggs" };
            //db.Customers.Attach(cust);
            //db.Entry(cust).State=EntityState.Added;
            //2.没有主键值的做法
            var cust = new Customer() { Name="xuming"};
            db.Customers.Add(cust);

            db.SaveChanges();

            db.Customers.AsEnumerable().Dump("After inserting");

            //Update 更新
            cust.Name = "Bloggs2";
            //db.Entry(cust).State=EntityState.Modified;
            db.SaveChanges();                 // Updates the customer

            db.Customers.AsEnumerable().Dump("After updating");


            //Delete 删除
            db.Customers.Remove(cust);
            db.SaveChanges();                 // Deletes the customer

            db.Customers.AsEnumerable().Dump("After deleting");
            Console.ReadKey();
        }
    }
}
